package com.ourteam.product.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.ui.dao.IProductUIActionDAO;
import com.ourteam.product.ui.dao.ProductUIActionDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIActionBean;

public class ProductUIActionSearchModel extends AbstractSearchModel<ProductUIActionDAOQueryBean> {

	private Long domainId;

	private long parentId = -1;
	
	private String code;
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public long getParentId() {
		return parentId;
	}

	public void setParentId(long parentId) {
		this.parentId = parentId;
	}

	public Long getDomainId() {
		return domainId;
	}

	public void setDomainId(Long domainId) {
		this.domainId = domainId;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductUIActionBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductUIActionDAOQueryBean queryBean) throws Exception {
		ProductUIActionDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		if (domainId != null && domainId != 0) {
			criteria.andDomainIdEqualTo(domainId);
		}
		if (parentId != -1) {
			criteria.andParentIdEqualTo(parentId);
		}
		
		if(StringUtils.isNotBlank(code)) {
			criteria.andCodeLike(code);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(IProductUIActionDAO.SortIndex);
		}
	}

}
